<template>
	<view class="page">
		<header-info :data="show.baseInfo"></header-info>

		<u-tabs :list="tabs" :is-scroll="false" :current="tabIndex" bg-color="transparent" @change="tabChange"></u-tabs>

		<view class="panel">
			<base-info v-if="tabIndex === 0" :data="show" :headList="headList"></base-info>
			<action-log v-if="tabIndex === 1" :id="id" :type="750"></action-log>
			<examine-info-show v-if="tabIndex === 2" :recordId="show.baseInfo.examineRecordId" :ownerUserId="show.baseInfo.createUserId"></examine-info-show>
		</view>

		<footer-bar :data="footerData" :auth="auth" :id="id" @onverify="onverify"></footer-bar>
	</view>
</template>

<script>
import headerInfo from './components/headerInfo';
import baseInfo from './components/baseInfo';
import actionLog from '../common/actionLog';
import examineInfoShow from '../common/examineInfoShow';
import footerBar from './components/footerBar';
export default {
	components: {
		headerInfo,
		baseInfo,
		actionLog,
		examineInfoShow,
		footerBar,
	},
	data: () => ({
		// 权限
		auth: {},
		// 详细信息
		show: {
			baseInfo: {},
		},
		// 选项卡数据
		tabs: [{ name: '基本信息' }, { name: '操作记录' }, { name: '审批记录' }],
		// 选项卡索引
		tabIndex: 0,
		// 基本信息表头
		headList: [],
		// footerbar 所需数据
		footerData: {},
	}),
	computed: {
		async psi() {
			return uni.getStorageSync('psi');
		},

		isDirector() {
			let is_director = false;
			if (this.psi.querystorehouse && this.psi.querystorehouse.querystorehouseDirector && this.action.type != 'export') {
				is_director = true;
			}
			return is_director;
		},
	},
	methods: {
		async getAuth() {
			let auth = uni.getStorageSync('authList');
			if (auth.crm) {
				this.auth = auth.crm.quotation;
				console.log(this.auth);
			}
		},
		// 获取详细
		async getshow() {
			let data = {
				quotationId: this.id,
			};
			let res = await this.$api.customer.quotation.show(data);
			if (res.code == 200) {
				this.show = res.data || {};
				this.getExaminRecordList();
			}
		},
		// tab切换
		tabChange(index) {
			this.tabIndex = index;
		},
		// 获取 审批历史
		async getExaminRecordList() {
			let data = {
				recordId: this.show.baseInfo.examineRecordId,
				ownerUserId: this.show.baseInfo.createUserId,
			};
			let res = await this.$api.customer.common.examineRecordList(data);
			if (res.code === 200) {
				this.examineRecordList = res.data || {};
				this.footerData = Object.assign(this.show.baseInfo, {
					examineType: this.examineRecordList.examineType,
					isCheck: this.examineRecordList.isCheck,
					isRecheck: this.examineRecordList.isRecheck,
				});
				console.log(this.footerData);
			}
		},
		// 基本信息的授权表头信息
		initTableHeader() {
			this.headList = [
				{ name: '产品名称', fieldName: 'productName', width: '130' },
				{ name: '型号', fieldName: 'productModel', width: '130' },
				{ name: '单价', fieldName: 'productPrice', width: '80' },
			];
			if (this.isDirector) {
				this.headList.push({ name: '总监单价', fieldName: 'directorPrice', width: '80' }, { name: '结算单价', fieldName: 'settlementPrice', width: '80' });
			}
			this.headList.push({ name: '数量', fieldName: 'productNumber', width: '80' }, { name: '单位', fieldName: 'unit', width: '80' }, { name: '总价', fieldName: 'totalPrice', width: '80' }, { name: '备注', fieldName: 'remark' });
		},
		// 审核操作成功
		onverify() {
			this.getshow();
		},
	},
	watch: {},

	// 周期函数--监听页面加载
	onLoad(options) {
		this.id = options.id;
		this.getAuth();
		this.getshow();
		this.initTableHeader();
	},
	// 周期函数--监听页面初次渲染完成
	onReady() {},
	// 周期函数--监听页面显示
	onShow() {},
	// 周期函数--监听页面隐藏
	onHide() {},
	// 周期函数--监听页面卸载
	onUnload() {},
	// 页面处理函数--监听用户下拉动作
	onPullDownRefresh() {
		this.getAuth();
		this.getshow();
		this.initTableHeader();
		uni.stopPullDownRefresh();
	},
	// 页面处理函数--监听用户上拉触底
	onReachBottom() {},
	// 监听自定义标题栏按钮事件
	onNavigationBarButtonTap(e) {},
	// 页面处理函数--监听页面滚动
	/* onPageScroll(event) {}, */
	// 页面处理函数--用户点击右上角分享
	/* onShareAppMessage(options) {}, */
};
</script>

<style lang="scss" scoped>
.panel {
	background: #fff;
	margin-bottom: 20px;
	padding: 5px;
}

.u-tabs /deep/ {
	.u-tab-bar {
		display: none;
	}
}
</style>
